<?php
namespace Container;

class Map
{
    private $maps           = NULL;
    private $mapP1Map       = NULL;
    private $mapP2Map       = NULL;

    public function __construct()
    {
        $this->maps         = array();
        $this->mapP1Map     = array();
        $this->mapP2Map     = array();
    }

    public function addMap($p1, $p2)
    {
        $map_id                 = count($this->maps);
        $this->maps[$map_id]    = new \Entity\Map($map_id, $p1, $p2);
        
        $this->mapP1Map[$p1]    = $this->maps[$map_id];
        $this->mapP2Map[$p2]    = $this->maps[$map_id];
    }
    
    public function delMap($id)
    {
        unset($this->mapP1Map[$this->maps[$id]->getP1()]);
        unset($this->mapP2Map[$this->maps[$id]->getP2()]);
        unset($this->maps[$id]);
    }

    public function getMap($id)
    {
        return $this->maps[$id];
    }
    
    public function getMapByPlayerId($player_id)
    {
        if (isset($this->mapP1Map[$player_id]))
        {
            return $this->mapP1Map[$player_id];
        }
        else if (isset($this->mapP2Map[$player_id]))
        {
            return $this->mapP2Map[$player_id];
        }
        return NULL;
    }
    
    public function issetMap($id)
    {
        return isset($this->maps[$id]);
    }
    
    public function countMaps()
    {
        return count($this->maps);
    }
    
    public function getMaps()
    {
        return $this->maps;
    }
}

#eof
